<%@ page language="java" import="java.util.*,com.newcrm.config.*,com.newcrm.util.Util,com.newcrm.bean.*,java.util.List,java.util.Map" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	User user = (User) session.getAttribute("user");
  Map<Integer, CompanyInfo> companys = (Map<Integer, CompanyInfo>) application.getAttribute(Const.APPLICATION_COMPANYS);
  CompanyInfo companyInfo = companys.get(Integer.valueOf(user.companyId));
  List<User> users = companyInfo.users;
  List<Group> allGroups = companyInfo.getAllGroups();

  // 获取产品信息
  ProductInfo productInfo = Config.getInstance().productInfo;
  String productName = productInfo.productName;

  // 用户所属部门
  Group userGroup = companyInfo.getGroupById(user.groupId);

  String viewCustomerIds = (String) request.getAttribute("viewCustomerIds");
  if (viewCustomerIds == null) {
    viewCustomerIds = "";
  }

  Object obj = session.getAttribute("voip");
  String voipAppID = "";
  String voipName = "";
  String voipPwd = "";
  String voipServerIP = "";
  if (obj != null) {
    Map<String, Object> voip = (Map<String, Object>) obj;
    voipAppID = (String)voip.get("AppID");
    voipName = (String)voip.get("UserName");
    voipPwd = (String)voip.get("UserPwd");
    voipServerIP = (String)voip.get("ServerIP");
  }

  Integer loginNum = (Integer) request.getAttribute("loginNum");
  if (loginNum == null) {
    loginNum = 0;
  }
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>工作台</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <meta name="renderer" content="webkit"/>
  <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  <link rel="shortcut icon" href="<%=request.getContextPath()%>/images/qikebao.ico" />
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/all.css?ver=<%=Const.VERSION%>">
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/datepicker.css" />
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/bootstrap-datetimepicker.min.css" />
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/magnific-popup.css">
<%if (loginNum <= 1) {%>
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/jquery.pagewalkthrough.min.css">
<%}%>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery-1.11.1.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery.sparkline.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/raphael-min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/morris.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/bootstrap.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery-ui.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery.bootstrap-growl.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/moment.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/bootstrap-datepicker.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/bootstrap-datetimepicker.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/daterangepicker.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery.magnific-popup.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery.cookie.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/popbox.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/json2.js?ver=<%=Const.VERSION%>"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/common.js?ver=<%=Const.VERSION%>"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/rightTask.js?ver=<%=Const.VERSION%>"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/dashboard.js?ver=<%=Const.VERSION%>"></script>
<%if (loginNum <= 1) {%>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery.pagewalkthrough.min.js?ver=<%=Const.VERSION%>"></script>
<%}%>
  <script>
    var userId = "<%=user.userId%>";
    var groupId = "<%=user.groupId%>";
    var viewCustomerIds = "<%=viewCustomerIds%>";
    var loginUserId = "<%=user.userId%>";
    var allUsers = new Array();
    <%if (users != null) {
        for (User u:users) { %>
    allUsers.push({id:"<%=u.userId%>",name:"<%=Util.UEncode(u.name)%>",photo:"<%=u.imgPath%>",groupId:<%=u.groupId%>});
    <%  }
      } %>

    $(function() {
<%if (voipName != null && voipName.length() > 0) {
  if (("ucpaas.qikebao.com").equals(voipServerIP)) { %>
      $.getJSON("<%=request.getContextPath()%>/voip/account?appId=<%=Util.HTMLEncode(voipAppID)%>", function(item) {
        if (item) {
          if (item.createTime.length > 0) {
            $("#createTime").text(item.createTime.split(" ")[0]);
          }
          $("#balance").text(item.balance);
          $("#dialFee").text(item.fee);
        }
      });
<%}
}%>
<%if (loginNum <= 1) {%>
      $('body').pagewalkthrough({
        name: 'introduction',
        buttons: {
          jpwClose: {
            i18n: '关闭向导页面'
          },
          jpwNext: {
            i18n: '下一步 &rarr;'
          },
          jpwPrevious: {
            i18n: '&larr; 上一步'
          },
          jpwFinish: {
            i18n: '结束 &#10004;'
          }
        },
        steps: [{
           popup: {
               content: '#walkthrough-1',
               type: 'modal'
           }
        }, {
            wrapper: '.profile-info',
            popup: {
                content: '#walkthrough-2',
                type: 'tooltip',
                position: 'left'
            }
        }, {
            wrapper: '#sidebar ul',
            popup: {
                content: '#walkthrough-3',
                type: 'tooltip',
                position: 'right'
            }
        }, {
            wrapper: '#help',
            popup: {
                content: '#walkthrough-4',
                type: 'tooltip',
                position: 'right'
            }
        }, {
            wrapper: 'div.appdownload span',
            popup: {
                content: '#walkthrough-5',
                type: 'tooltip',
                position: 'top'
            }
        }]
      });

      // Show the tour
      $('body').pagewalkthrough('show');
<%}%>
    });
  </script>
</head>
<body class="dashboard">
  <jsp:include page="topNavi.jsp" flush="true"/>
  <div class="main-page">
    <table>
    <tr>
      <td class="main-body">
        <div class="topHeader">
<% if (!user.isAdmin && !user.isGroupAdmin) { %>
          <div class='leftMenu'><span>我的工作台</span></div>
<% } else {%>
          <div class='popbox leftMenu'>
            <a class='open' href="#"><span id="viewmodeMessage">我的工作台</span> <i class="fa fa-chevron-down"></i></a>
            <div class='collapse'>
              <div class='box'>
                <div class='arrow'></div><div class='arrow-border'></div>
                <form>
                <h1>请选择查看方式：</h1>
                <p class="text-align:left;padding:5px 0px;margin:0px;">
                  <div class="top10"><label>部门:</label> <select id="groupId">
<% if (user.isAdmin) { %>
                    <option value="">全公司情况概要</option>
                    <option value="0">无部门</option>
<%  if (allGroups != null) {
      for (Group group:allGroups) { %>
                    <option value="<%=group.getId()%>"><%=group.getIndentName()%></option>
<%    }
    }
  } else {
    if (userGroup != null) {
      for (Group group:userGroup.getAllGroups()) { %>
                  <option value="<%=group.getId()%>"><%=group.getIndentName()%></option>
<%    }
    }
  }%>

                  </select>
                  </div>
                  <div class="top10">
                  <label>员工:</label> <select id="memeberId" >
                    <option value="">全部员工</option>
                  </select>
                  </div>
                  <div class="top10">
                    <a id="changeUser-link" class="button blue small closePopbox" href="#"><i class="fa fa-check"></i> 确定</a>
                  </div>
                </p>
                </form>
              </div>
            </div>
          </div>
          <div class="clearfix"></div>
<% } %>
       </div>
       <%--
<% if (user.isAdmin) { %>
       <div class="header">
          呼叫中心账号情况
        </div>
        <div class="boxs">
          <ul class="small">
            <li>
              <i class="fa fa-calendar fa-2x"></i>
              <div id="createTime">#</div>
              <p>开通时间</p>
            </li>
            <li>
              <i class="fa fa-yen fa-2x"></i>
              <div id="balance">0</div>
              <p>外呼余额 (元)</p>
            </li>
            <li>
              <i class="fa fa-yen fa-2x"></i>
              <div id="dialFee">0</div>
              <p>外呼资费 (元/分钟)</p>
            </li>
          </ul>
        </div>
        <div class="clearfix"></div>
<%}%>
        --%>
        <div class="header">
          今日概要
          <div class="right date">
            <div class="input-prepend input-group"><span class="add-on input-group-addon"><i class="fa fa-calendar"></i></span><input type="text" id="searchDate" class="daterangepickerinput form-control" value="" /></div>
          </div>
        </div>
        <div class="boxs">
          <ul class="small">
            <li>
              <a href="<%=request.getContextPath()%>/parties?notContactType=1">
                <i class="fa fa-user fa-2x"></i>
                <div id="notContactedNum"></div>
                <p>未联系客户数量</p>
              </a>
            </li>
            <li>
              <a id="contactDate_link" href="<%=request.getContextPath()%>/parties?contactDate=<%=Util.date2Str2(new Date())%>">
                <i class="fa fa-check fa-2x"></i>
                <div id="contactedNum"></div>
                <p>已联系客户数量</p>
              </a>
            </li>
            <li>
              <a id="nextDate_link" href="<%=request.getContextPath()%>/parties?nextDate=<%=Util.date2Str2(new Date())%>">
                <i class="fa fa-bell fa-2x"></i>
                <div id="nextContactedNum"></div>
                <p>需要联系客户数量</p>
              </a>
            </li>
            <li>
              <a href="<%=request.getContextPath()%>/deals?dealStatus=1">
                <i class="fa fa-yen fa-2x"></i>
                <div id="pendingDealNum"></div>
                <p>跟进中销售机会</p>
              </a>
            </li>
          </ul>
        </div>
        <div class="clearfix"></div>

        <div class="header">最近一周工作情况</div>
        <div class="sparkline">
          <div class="panel">
            <h1>最近联系客户数量</h1>
            <div id="contactparkline" class="line"></div>
          </div>
          <div class="panel">
            <h1>新创建客户数量</h1>
            <div id="createparkline" class="line"></div>
          </div>
        </div>
        <div class="clearfix"></div>
        <div class="header">客户分析统计</div>
        <div class="boxs">
          <ul class="big">
            <li>
             <p>总客户数</p>
             <div id="totalNum"></div>
            </li>
            <li>
              <p>已联系过客户数</p>
              <div id="totalContactedNum"></div>
            </li>
            <li>
              <div class="char" id="customerchar"></div>
            </li>
          </ul>
        </div>
      </td>
      <td class="main-sidebar">
        <div class="content">
          <h2 class="clearfix">任务</h2>
          <div class="tasklist overdue" id="overdueTasks">
            <h6> 已过期 </h6>
            <ul class="tasks"></ul>
          </div>
          <div class="tasklist" id="todayTasks">
            <h6> 今天 </h6>
            <ul class="tasks"></ul>
          </div>
          <div class="tasklist" id="tomorrowTasks">
            <h6> 明天 </h6>
            <ul class="tasks"></ul>
          </div>
          <div class="tasklist" id="thisWeekTasks">
            <h6> 本周 </h6>
            <ul class="tasks"></ul>
          </div>
          <div class="tasklist" id="nextWeekTasks">
            <h6> 下周 </h6>
            <ul class="tasks"></ul>
          </div>
          <div class="tasklist" id="laterTasks">
            <h6> 以后 </h6>
            <ul class="tasks"></ul>
          </div>
          <h2>最近联系客户</h2>
          <ul class="items" id="recentlyVisitedCustomers"></ul>
        </div>
      </td>
    </tr>
    </table>
  </div>
  <div class="movebox" id="updateTask">
    <div class='arrow'></div><div class='arrow-border'></div>
    <form class="task">
      <h3>修改任务</h3>
      <p class="task_body">
        <input id="update_taskId" type="hidden" value="" />
        <input class="autofocus" id="update_taskTitle" size="25" type="text" />
      </p>
      <div>
        <h5>到期时间</h5>
        <p>
          <div class="datetimepicker_container"><input class="autofocus dueDate" id="update_dueDate" size="25" type="text" /></div>
        </p>
        <h5>任务负责人</h5>
        <p>
          <select id="update_responsibleUserId" class="responsibleUserId"></select></p>
        <h5>任务分类</h5>
        <p>
          <select id="update_categoryId" class="categoryId"></select>
          <% if (user.isAdmin) {%>
          <a href="<%=request.getContextPath()%>/taskcategory" class="edit_categories">编辑分类</a>
          <% }%>
        </p>
        <p>
          <input class="checkbox" id="update_taskVisible" type="checkbox" value="1" />
          <label for="update_taskVisible">所有人可以看见这个任务</label>
        </p>
      </div>
      <div class="submit">
        <a id="update_task_button" class="button blue small closePopbox" href="#"><i class="fa fa-check"></i> 修改任务</a>
        &nbsp;&nbsp;<a href="#" class="closePopbox" id="update_task_cancel_link">取消</a>
      </div>
    </form>
  </div>
<%if (loginNum <= 1) {%>
  <div id="walkthrough-content" class="hide">
    <div id="walkthrough-1">
      <h1>欢迎使用<%=productName%>客户管理系统</h1>

      <p><%=productName%>是一个实用为主的客户管理系统，特别适合营销型中小企业使用</p>
      <p><br/>点击[下一步]查看更多</p>
    </div>

    <div id="walkthrough-2">
      <br/><br/>首先第一步，您可以在系统设置中的[员工管理]中，给您的同事创建账号。每个同事都可以使用自己的账号登陆<%=productName%>软件。
    </div>

    <div id="walkthrough-3">
      左侧的导航条中，您可以查看客户信息，任务，销售机会，检索备注，以及统计分析。
    </div>

    <div id="walkthrough-4">
      使用中有问题，可以点击[在线帮助]，这里我们整理了<%=productName%>使用中常见的问题。
    </div>
    <%--
    <div id="walkthrough-5">
      <div style="padding-left:140px;width:500px;"><%=productName%>也提供了安卓的手机版（适合于部署安装在云服务器上的用户使用），也请关注我们的微信公众账号，了解最新的软件介绍。</div>
    </div>
    --%>
  </div>
<%}%>
</body>
</html>